<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<include file="Public:base" />
<script type="text/javascript">
$(document).ready(function() {

	jQuery.validator.addMethod("checkusername", function (val, element) {
        var checkResult = false;
        var term = "";
        var username = $("[name='username']").val();
        if (username) {
        	term += "username=" + username;
        }else{
        	return true
        }
        $.ajax({
            type: 'post',
            url: "__URL__/checkusername",
            data: term,
            async: false,
            success: function (data) {
                if ($.trim(data) == 'ok') {
                    //表示 没通过 验证 
                	checkResult = false;
                } else {
                	//返回 true 表示 通过验证 
                    checkResult = true;
                }
            }
        });
        return checkResult;
    }, "此登陆名已存在");
	
	$("#adminform").validate({
		
		errorPlacement: function (error, element) {
            error.appendTo(element.parent().find('label'));
            element.parent().addClass("has-error");
        },
        //获取焦点时不验证 
        focusInvalid: false,   
        onkeyup: false ,
		
	    rules: {
	        'username': {
	            required: true,
	            checkusername:true
	        },
	        'password': {
	            required: true,
	            rangelength:[6,15]
	        }
	    },
	    messages: {
	        'username': {
	            required: "请输入用户名 "
	        },
	        'password': {
	            required: "请输入用户密码",
	            rangelength:"密码长度为 6-15位"
	        }
	    }
	});
});

</script>
</head>
<body>
<include file="Public:header" />
<div class="home-index">
	<div class="col-xs-12">
		<h2>添加管理员</h2>

		<div class="edit-user">
			<form  id="adminform" role="form" method="post" action="__URL__/create">

				<div class="form-group">
					<label >用户名:</label>
					<input type="text" name="username" class="form-control" placeholder="请输入用户名"></div>
				<div class="form-group">
					<label>密码:</label>
					<input type="password" name="password" class="form-control" placeholder="请输入密码"></div>
				<button type="submit" class="btn btn-primary">提交</button>
			</form>

		</div>
	</div>
</div>
</body>
</html>